package com.yhcrt.utils;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletRequest;

import com.yhcrt.entiy.Group;

/**
 * 参数解码
 * @author 陈伟
 * 2018年7月21日 下午3:26:08
 */
public class RequestParam {
	
	public static HashMap<String ,String> getQueryString(HttpServletRequest request) {
		HashMap<String, String> params = new LinkedHashMap<String, String>();
		String value = request.getQueryString();
		if (StringUtils.isNotBlank(value)) {
			try {
				value =java.net.URLDecoder.decode(Base64Util.base64decode(value), "UTF-8");
				String values[] = value.split("&");
				for (String v : values) {
					String[] p = v.split("=");
					params.put(p[0], p[1]);
				}
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return params;
	}
	
	public static Group getGroup(HttpServletRequest request) {
		HashMap<String, String> params = RequestParam.getQueryString(request);
		Integer cid = Integer.parseInt(params.get("cid"));
		String  name = (params.get("name"));
		return new Group(cid,name);
	}
}
